package com.zzh.takeoutapp.broad;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;

/**
 * @author zzh
 * @Name:
 * @Description:
 * @date
 * @time
 * @copyright
 */
public class NetWorkStatusService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new LocalBinder();
    }

    public final class LocalBinder extends Binder {
        public NetWorkStatusService getService() {
            return NetWorkStatusService.this;
        }
    }

    public void asyncSendPerson(final String name) {
        // 休息5秒，模拟异步任务
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //可以在子线程中直接发送广播
                sendContentBroadcast(name);
            }
        }).start();
    }

    /**
     * 发送广播
     *
     * @param name
     */
    protected void sendContentBroadcast(String name) {
        Intent intent = new Intent();
        intent.setAction("sendContentBroadcast");
        intent.putExtra("name", name);
        sendBroadcast(intent);
    }
}
